import java.util.*;
//创建节点
class TreeNode{
    char val;
    TreeNode left;
    TreeNode right;
    public TreeNode(char val){
        this.val = val;
    }
}
public class Main{
    //先序遍历,递归创建一个二叉树
    public int i = 0;//不建议定义静态变量
    public TreeNode createTree(String s){
        TreeNode root = null;
        if(s == null){
            return root;
        }
        if(s.charAt(i) != '#'){
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = createTree(s);
            root.right = createTree(s);
            
        }else{
            i++;
        }
        return root;
    }
    
    //后序遍历:左->右->根
    public void inOrder(TreeNode root){
        if(root == null){
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
        

    public static void main (String [] args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String s = scanner.nextLine();
            Main m = new Main();
        TreeNode root = m.createTree(s);
        m.inOrder(root);
        }
             
              
        
    }
              
 }